//
//  PPPhoto.m
//  pickpic
//
//  Created by 胡文广 on 2017/4/12.
//  Copyright © 2017年 MicroDream. All rights reserved.
//

#import "PPPhoto.h"
#import "PPHomeAlbumModel.h"
#import "PPTemplateCoverFrame.h"
#import "PPAlbumScrollView.h"
#import "PPTemplateDescModel.h"
#import "PPTemplateInnerModel.h"
#import "PPEditTextView.h"
#import "PPHomeEbookModel.h"
#import "PPDescText.h"
#import "PPCommonPicturesUploaderManager.h"
#import "PPUploadPicture.h"
#import "PPToolBarView.h"
#import "PPInsetLabel.h"
#define kUserIconWH 30
#define kCodeImageWH 140
#define ScreenWidth [UIScreen mainScreen].bounds.size.width
#define ScreenHeight [UIScreen mainScreen].bounds.size.height

#define kCoverTitleMargin 80
#define kNormalDescMargin 15 //左右边距

#define kNormalTitleFont ([UIFont boldSystemFontOfSize:36])

#define kNormalCoverTitleLineDistance 15

#define kNormalDescLineDistance 10
#define kDescMaxSize 140
@interface PPPhoto()<UITextViewDelegate,PPAlbumScrollViewDelegate,PPToolBarViewDelegate>
@property (nonatomic,strong) PPInsetLabel *descLabel;
@property (nonatomic,strong) UILabel *descLineLabel;

@property (nonatomic,strong) UILabel *coverTitleLabel;
@property (nonatomic,strong) UILabel *coverNickNameLabel;
@property (nonatomic,strong) UIImageView *coverUserPhoto;
@property (nonatomic,strong) UILabel *coverUserPicpick;
@property (nonatomic,strong) UIView *coverView;
@property (nonatomic,strong) UIImageView *codeImg;
//@property (nonatomic,strong) UILabel *codeDesc;

@property (nonatomic,strong) UILabel *albumTitleL;



@property (nonatomic,strong) PPAlbumScrollView *albumScrollView;


@property (nonatomic,strong) PPAlbumScrollView *innerScrollView;
@property (nonatomic,strong) UIImageView *innerBgView;
@property (nonatomic,strong) PPDescText *innerDescTextV;
@property (nonatomic,strong) UILabel *innerPageLabel;

//键盘属性
@property (nonatomic, assign) NSTimeInterval  time;
@property (nonatomic, assign) NSUInteger  curve;
@property (nonatomic, assign) CGFloat  keyboardHeight;

@property (nonatomic,strong) PPEditTextView *editView;

@property (nonatomic,assign) BOOL isEditAlbumImage;


@property (nonatomic,strong) NSString *currentDesc;

@property (nonatomic,assign) BOOL isEditDesc;

@property (nonatomic,strong) UIImageView *descBg;

@property (nonatomic,assign) CGFloat descHeight;

//@property (nonatomic,strong) UIView *toolBarView;

@property (nonatomic,strong) PPToolBarView *toolBar;

@property (nonatomic,strong) UIImage *orgImage;
@property (nonatomic,strong) UIBezierPath *recCoverPath;
@property (nonatomic,strong) CAShapeLayer *shapeCoverLayer;

@property (nonatomic,strong) UIBezierPath *recPath;
@property (nonatomic,strong) CAShapeLayer *shapeLayer;

@property (nonatomic,assign) BOOL isEditTitle;
@property (nonatomic,strong) CAShapeLayer *shapeTitleLayer;

@property (nonatomic,assign) BOOL isEdit;

@property (nonatomic,assign) BOOL isFirstGoto;
@property (nonatomic,assign) BOOL isEditPhoto;
@end
@implementation PPPhoto

- (CAShapeLayer *)shapeLayer{
    
    if (!_shapeLayer) {
        //        self.recPath =[UIBezierPath bezierPathWithRect:self.albumImageView.frame];
        self.recPath =[UIBezierPath bezierPathWithRect:CGRectMake(0, 0, self.innerModel.frameWidth, self.innerModel.frameHeight)];
        _shapeLayer=[CAShapeLayer layer];
        //        _shapeLayer.frame = self.albumImageView.frame;
        _shapeLayer.frame = CGRectMake(0, 0, self.innerModel.frameWidth, self.innerModel.frameHeight);
        _shapeLayer.strokeColor = [COLORA(255, 221,23) CGColor];
        _shapeLayer.fillColor = [[UIColor clearColor] CGColor];
        _shapeLayer.lineWidth = 2.0f;
        _shapeLayer.path= self.recPath.CGPath;
    }
    return _shapeLayer;
}
- (CAShapeLayer *)shapeCoverLayer{
    
    if (!_shapeCoverLayer) {
        self.recCoverPath =[UIBezierPath bezierPathWithRect:CGRectMake(0, 0, self.coverFrame.boxWidth, self.coverFrame.boxHeight)];
        _shapeCoverLayer=[CAShapeLayer layer];
        _shapeCoverLayer.frame = CGRectMake(0, 0,self.coverFrame.boxWidth, self.coverFrame.boxHeight);
        _shapeCoverLayer.strokeColor = [COLORA(255, 221,23) CGColor];
        _shapeCoverLayer.fillColor = [[UIColor clearColor] CGColor];
        _shapeCoverLayer.lineWidth = 2.0f;
        _shapeCoverLayer.path= self.recCoverPath.CGPath;
    }
    return _shapeCoverLayer;
}
- (CAShapeLayer *)shapeTitleLayer{
    
    if (!_shapeTitleLayer) {
        self.recCoverPath =[UIBezierPath bezierPathWithRect:CGRectMake(0,([self.albumTitleL labelText:self.albumTitleL.text width:self.coverFrame.titleWidth]?15:0), self.coverFrame.titleWidth, [self.albumTitleL labelText:self.albumTitleL.text width:self.coverFrame.titleWidth]?68:self.coverFrame.titleHeight)];
        _shapeTitleLayer=[CAShapeLayer layer];
        _shapeTitleLayer.frame = CGRectMake(0, 0,self.coverFrame.titleWidth, self.coverFrame.titleHeight);
        _shapeTitleLayer.strokeColor = [COLORA(255, 221,23) CGColor];
        _shapeTitleLayer.fillColor = [COLORA(255, 221,23) CGColor];
        _shapeTitleLayer.opacity = 0.4;
        _shapeTitleLayer.lineWidth = 2.0f;
        _shapeTitleLayer.path= self.recCoverPath.CGPath;
    }
    return _shapeTitleLayer;
}
- (UIImageView *)descBg{

    if (!_descBg) {
        _descBg = [[UIImageView alloc] init];
    }
    return _descBg;
}
- (PPEditTextView *)editView{

    if (!_editView) {
        _editView = [PPEditTextView editTextView];
        _editView.eidtTextView.delegate = self;
        _editView.backgroundColor = WHITE;
        _editView.alpha = 0.9;
        _editView.eidtTextView.returnKeyType = UIReturnKeyDone;
    }
    return _editView;
}
- (instancetype)initWithFrame:(CGRect)frame{

    if (self = [super initWithFrame:frame]) {
        
        //不裁剪的话，缩放的时候会看到两边多余的部分
        self.clipsToBounds = YES;
        self.userInteractionEnabled  = YES;
        self.contentMode = UIViewContentModeScaleAspectFill;
        
        //keyboard
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWasShow:) name:UIKeyboardWillShowNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(isScrollViewEnable:) name:PPNotice_isEditImage object:nil];
        
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endEditAlbum) name:PPNotice_isEditImageChange object:nil];
        
        [self addObserver:self forKeyPath:@"isEdit" options:
         NSKeyValueObservingOptionOld|NSKeyValueObservingOptionNew context:nil];
        
        
        
    }
    return self;
}

- (void)endEditAlbum{
    
//    self.isEditAlbumImage = NO;
    
//    [self.albumScrollView noticeEditEnable];
    
//    [self.innerScrollView noticeEditEnable];
    
    if (self.coverFrame) {
        self.coverFrame = self.coverFrame;
        
    }

    if (self.innerModel) {
//        NSArray *array = [self.innerPageLabel.text componentsSeparatedByString:@"/"];
//        PPTemplateInnerModel *innerModel = self.innerModel;
//        innerModel.picModel = self.pics[[[array firstObject] integerValue] - 1];
//        
//        self.innerScrollView.innerModel = self.innerModel;
    }
    [self.innerScrollView cancelEdit];
    [self.albumScrollView cancelEdit];
    
    //完成
    [self hiddenToolBar];
    
    //可以滑动到下一页
    [[NSNotificationCenter defaultCenter] postNotificationName:PPNotice_isEditImage object:@(NO)];
    
    
    
}

- (void)isScrollViewEnable:(NSNotification *)notice{
    
    self.isEditAlbumImage = [notice.object boolValue];
    
    
//    self.innerDescTextV.editable = self.isEditAlbumImage;
//    
//    [self descTextViewText:self.currentDesc isEdit:self.isEditAlbumImage];
    
    
    
}

- (UILabel *)innerPageLabel{

    if (!_innerPageLabel) {
        
        _innerPageLabel = [[UILabel alloc] init];
    }
    return _innerPageLabel;
}
- (PPDescText *)innerDescTextV{

    if (!_innerDescTextV) {
        _innerDescTextV = [[PPDescText alloc] init];
        _innerDescTextV.delegate = self;
        _innerDescTextV.editable = NO;
        _innerDescTextV.bounces = NO;
//        _innerDescTextV.contentInset = UIEdgeInsetsMake(0, 20, 0, 20);
//        _innerDescTextV.textAlignment = NSTextAlignmentCenter;
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(startEdit:)];
        
        [_innerDescTextV addGestureRecognizer:tap];
    }
    return _innerDescTextV;
}
- (void)startEdit:(UITapGestureRecognizer *)rec{

    self.innerDescTextV.editable = YES;
    self.isEditAlbumImage = YES;
    [self descTextViewText:self.currentDesc isEdit:self.isEditAlbumImage];
    
    if ([rec.view isKindOfClass:[PPDescText class]]) {
        
        [self.innerDescTextV becomeFirstResponder];
    }
    
//    self.innerScrollView.userInteractionEnabled = NO;
    
}
- (UIView *)innerBgView{

    if (!_innerBgView) {
        _innerBgView = [[UIImageView alloc] init];
        _innerBgView.userInteractionEnabled = YES;
    }
    return _innerBgView;
}
- (PPAlbumScrollView *)innerScrollView{
    
    if (!_innerScrollView) {
        _innerScrollView = [[PPAlbumScrollView alloc] init];
        _innerScrollView.delegate = self;
        
    }
    return _innerScrollView;
    
}

- (PPAlbumScrollView *)albumScrollView{
    
    if (!_albumScrollView) {
        _albumScrollView = [[PPAlbumScrollView alloc] init];
        _albumScrollView.delegate = self;
    }
    return _albumScrollView;
    
}

#pragma mark -编辑图片完成
- (void)albumCoverViewEndEditView:(PPAlbumScrollView *)view cutFrame:(CGRect)cutFrame{

//    [[NSNotificationCenter defaultCenter] postNotificationName:PPNotice_ChangeAlbumsPic object:@{kCutPicKey:@(self.tag),kCutPicValue:[UIImage imageFromView:self atFrame:view.frame]}];
//    CGRect rec =CGRectMake(self.coverFrame.boxXaxis, self.coverFrame.boxYaxis - 64, self.coverFrame.boxWidth, self.coverFrame.boxHeight);

    
//    PPLog(@"操作了第%zd张",self.tag);
    
    [[NSNotificationCenter defaultCenter] postNotificationName:PPNotice_ChangeAlbumsPic object:@{kCutPicKey:@(self.tag),kCutPicValue:[UIImage pq_cutScreenWithView:self cutFrame:cutFrame]}];
    
    
    
    
    
    
    
    
    
    
}
- (UILabel *)albumTitleL{

    if (!_albumTitleL) {
        _albumTitleL = [[UILabel alloc] init];
        _albumTitleL.textAlignment = NSTextAlignmentCenter;
        _albumTitleL.numberOfLines = 2;
//        _albumTitleL.layer.shadowColor = [UIColor colorWithHexString:@"0X000000"].CGColor;//阴影颜色
//        _albumTitleL.layer.shadowOffset = CGSizeMake(0.5, 0.5);//偏移距离
//        _albumTitleL.layer.shadowOpacity = 0.5;//不透明度
//        _albumTitleL.layer.shadowRadius = 1;//半径
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(modifyTitle:)];
        [_albumTitleL addGestureRecognizer:tap];
    }
    return _albumTitleL;
}
//- (UIImageView *)albumCoverImg{
//
//    if (!_albumCoverImg) {
//        _albumCoverImg = [[UIImageView alloc] init];
////        _albumCoverImg.backgroundColor = RED;
//    }
//    return _albumCoverImg;
//}
//- (UILabel *)codeDesc{
//    
//    if (!_codeDesc) {
//        _codeDesc = [[UILabel alloc] init];
//        _codeDesc.font = PPFONTSIZE(14.0f);
//        _codeDesc.textAlignment = NSTextAlignmentCenter;
//        _codeDesc.textColor = WHITE;
//        _codeDesc.text = @"长按二维码下载 PickPic";
//    }
//    return _codeDesc;
//}
- (UIImageView *)codeImg{
    if (!_codeImg) {
        _codeImg = [[UIImageView alloc] init];
        _codeImg.image = [UIImage imageNamed:@"code_icon"];
    }
    return _codeImg;
}
- (UIView *)coverView{

    if (!_coverView) {
        _coverView = [[UIView alloc] init];
        _coverView.backgroundColor = BLACK;
        _coverView.alpha = 0.9;
    }
    return _coverView;
}
- (UILabel *)coverTitleLabel{

    if (!_coverTitleLabel) {
        _coverTitleLabel = [[UILabel alloc] init];
//        _coverTitleLabel.font = PPFONTSIZE(28.0f);
        _coverTitleLabel.textAlignment = NSTextAlignmentCenter;
        _coverTitleLabel.textColor = WHITE;
        _coverTitleLabel.numberOfLines = 0;
    }
    return _coverTitleLabel;
}
//- (UIImageView *)coverUserPhoto{
//    
//    if (!_coverUserPhoto) {
//        _coverUserPhoto = [[UIImageView alloc] init];
//        _coverUserPhoto.layer.cornerRadius = kUserIconWH*0.5;
//        _coverUserPhoto.layer.masksToBounds = YES;
//    }
//    return _coverUserPhoto;
//}
- (UILabel *)coverNickNameLabel{
    
    if (!_coverNickNameLabel) {
        _coverNickNameLabel = [[UILabel alloc] init];
        _coverNickNameLabel.font = PPFONTSIZE(12.0f);
        _coverNickNameLabel.textColor = WHITE;
        _coverNickNameLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _coverNickNameLabel;
}
//- (UILabel *)coverUserPicpick{
//    
//    if (!_coverUserPicpick) {
//        _coverUserPicpick = [[UILabel alloc] init];
//        _coverUserPicpick.font = PPFONTSIZE(12.0f);
//        _coverUserPicpick.textColor = WHITE;
////        _coverUserPicpick.numberOfLines = 0;
//    }
//    return _coverUserPicpick;
//}

- (PPInsetLabel *)descLabel{
    if (!_descLabel) {
        _descLabel = [[PPInsetLabel alloc] init];
        _descLabel.font = PPFONTSIZE(15.0f);
        self.descLabel.textColor = WHITE;
        _descLabel.backgroundColor = CLEAR;
        self.backgroundColor = BLACK;
        _descLabel.textAlignment = NSTextAlignmentLeft;
        _descLabel.numberOfLines = 0;

    }
    return _descLabel;
}
///MARK：默认样式 相册描述
- (void)setDesc:(NSString *)desc{
    _desc = [desc copy];
    
    self.descLabel.text = _desc;
    
    UIFont *descFont;
    if ([NSString isFontDownloaded:self.innerModel.describeScript]) {
        descFont =PPFONT(_descModel.describeScript, _descModel.textFont);
    }else{
        descFont = PPFONTSIZE(_descModel.textFont>0?_descModel.textFont:15);
    }
    
    CGFloat lineSpace = kNormalDescLineDistance;
//    if (_descModel.textMargin > 0) {
//        lineSpace = self.descModel.textMargin;
//    }
//    
    [self.descLabel changeLineSpaceForLabelWithSpace:lineSpace - kLabelMargin text:_desc labelFont:descFont];

    if ([self.descModel.series isEqualToString:@"wave"]) {
        PPLog(@"傻逼的第一个描述");
        [self.descLabel changeLineSpaceForLabelWithSpace:3 text:_desc labelFont:descFont];
        self.descLabel.textAlignment = NSTextAlignmentCenter;
        
    }else{
        [self.descLabel textLabelAlbumtitle:_desc width:ScreenWidth-kNormalDescMargin*2];
    }
    
    if (self.lastStyle == PPPhotoCoverSytleNone) {
        self.clipsToBounds = NO;
        self.descBg.contentMode = UIViewContentModeScaleAspectFill;
        self.descBg.image = self.descImg;
        self.descBg.backgroundColor = CLEAR;
        [self addSubview:self.descBg];
        [self addSubview:self.coverView];
    }
    
    [self addSubview:self.descLabel];


}
#pragma mark -布局调整
- (void)layoutSubviews{

    [super layoutSubviews];
    
    self.toolBar.frame = CGRectMake(0, self.height - 44, self.width, 44);
    
     CGFloat updownMargin = 64/2; //整个屏幕距离居中
    
    if (![self.descModel.series isEqualToString:@"wave"]) {
    
        self.descLabel.bounds = CGRectMake(0, 0, self.width - kNormalDescMargin*2,self.height);
        self.descLabel.center = CGPointMake(self.center.x, self.center.y - updownMargin);
    }
    
    self.descBg.frame = self.bounds;
    self.coverView.frame = self.bounds;
    if (self.style == PPPhotoCoverSytleNone) {
        
        
        self.coverTitleLabel.bounds = CGRectMake(0, 0, self.width - kCoverTitleMargin, self.height);
        
        self.coverTitleLabel.center = CGPointMake(self.center.x, self.center.y - updownMargin);
        
        
        CGFloat h = 30;
        CGFloat nickNameW = [self rectWidthWithText:[PPAccountManager sharedInstance].account.profiles.name height:h font:PPFONTSIZE(12.f)];
        
        self.coverNickNameLabel.center = CGPointMake(self.width/2,self.height - 36);
        
        self.coverNickNameLabel.bounds = CGRectMake(0, 0,nickNameW, 21);
        

        

    }else{

        PPTemplateCoverFrame *coverFrame = self.coverFrame;
        
        //封面相框
        [self adjustCoverViewFrame:coverFrame];
        

        
        //封面标题
        [self adjustCoverTitleViewFrame:coverFrame];
        
        
        //封面用户名
        [self adjustCoverUserLabel:coverFrame];

        //相册描述
        if ([self.descModel.series isEqualToString:@"wave"]) {
        
            self.descLabel.bounds = CGRectMake(0, 0, self.width - kNormalDescMargin*2,self.height);
            self.descLabel.center = CGPointMake(self.center.x, self.center.y - updownMargin);
            
            CGSize titleSize = [self.descLabel.text boundingRectWithSize:CGSizeMake(self.width - kNormalDescMargin*2, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: PPFONTSIZE(_descModel.textFont)} context:nil].size;

            self.descLabel.frame = CGRectMake(kNormalDescMargin,self.height/2 - titleSize.height/2 - 64/2, self.width - kNormalDescMargin*2, (titleSize.height <= 20?titleSize.height + 18:titleSize.height + 21));
        }
        
        //内页
        self.innerBgView.frame = self.bounds;
        
        CGFloat innerH = self.innerModel.frameHeight;
        
        if ([self.innerModel.series isEqualToString:@"wave"]) {
            innerH = self.innerModel.frameWidth;
        }
        
        self.innerScrollView.frame = CGRectMake(self.innerModel.frameXaxis, self.innerModel.frameYaxis - 64 , self.innerModel.frameWidth,innerH);
        
        self.innerScrollView.cutRect = CGRectMake(self.innerModel.frameXaxis, self.innerModel.frameYaxis - 64 , self.innerModel.frameWidth, self.innerModel.frameHeight);

        
        
        [self adjustInnerViewFrame];
        
        self.shapeLayer.frame = self.innerScrollView.frame;
        
//        CGRect shareF = self.innerScrollView.frame;
//        self.shapeLayer.frame = CGRectMake(0, ([self.albumTitleL labelText:self.albumTitleL.text width:coverFrame.titleWidth]?shareF.origin.y + 40:shareF.origin.y), shareF.size.width, shareF.size.height);


        CGFloat pageX = self.innerModel.pageXaxis;
        if (self.innerModel.orderNum == 3 &&IS_IPHONE_6_PLUS) {
            pageX = self.innerModel.pageXaxis - 3;
        }
        
        self.innerPageLabel.frame = CGRectMake(pageX, self.innerModel.pageYaxis - 64, 40, 21);

    }
    
    if (self.lastStyle == PPPhotoLastCoverSytleNone) {
        self.coverView.frame = CGRectMake(0, 0, self.width, self.height+64);
        self.codeImg.bounds = CGRectMake(0,0 , kCodeImageWH, kCodeImageWH);
//        self.codeImg.center = CGPointMake(self.width/2, (self.height - 64)/2);
        self.codeImg.center = CGPointMake(self.width/2,self.height *0.5 -
                                  64);
//        self.codeDesc.frame = CGRectMake(0, CGRectGetMaxY(self.codeImg.frame)+5, self.width, 30);
        
    }else if(self.lastStyle == PPPhotoLastCoverSytleCustom){
        self.coverView.frame = CGRectMake(0, 0, self.width, self.height);
        self.codeImg.bounds = CGRectMake(0,0 , kCodeImageWH, kCodeImageWH);
//        self.codeImg.center = CGPointMake(self.width/2, (self.height - 64)/2);
        self.codeImg.center = CGPointMake(self.width/2,self.height *0.5-
                                          64);
//        self.codeDesc.frame = CGRectMake(0, CGRectGetMaxY(self.codeImg.frame)+5, self.width, 30);
        
        if (self.orderNum == 6) {
            self.codeImg.image = [UIImage imageNamed:@"wave_code"];
        }
        
    }else{
    
    }
    
//    self.albumTitleL.textColor = [UIColor redColor];
//    self.coverNickNameLabel.textColor = [UIColor blueColor];
//    self.descLabel.textColor = [UIColor redColor];
//    [self.albumTitleL sizeToFit];
//    [self.coverNickNameLabel sizeToFit];
    
//    self.albumTitleL.top = self.coverFrame.titleYaxis - 64;
//    self.albumTitleL.centerX = self.centerX;
    
//    self.coverNickNameLabel.top = self.coverFrame.userYaxis - 64;
//    self.coverNickNameLabel.centerX = self.centerX;
}

///MARK:默认样式
- (void)setAlbumCoverModel:(PPHomeAlbumModel *)albumCoverModel{

    _albumCoverModel = albumCoverModel;
    
    
    self.clipsToBounds = NO;
    self.contentMode = UIViewContentModeScaleAspectFill;
    self.image = _albumCoverModel.coverImage;
    
    self.coverTitleLabel.userInteractionEnabled = NO;
    self.coverTitleLabel.backgroundColor = CLEAR;
    self.coverTitleLabel.numberOfLines = 0;
    
    //标题行间距
    [self.coverTitleLabel changeLineSpaceForLabelWithSpace:kNormalCoverTitleLineDistance/2-kLabelMargin text:_albumCoverModel.title labelFont:kNormalTitleFont];

    //标题对齐方式
    [self.coverTitleLabel textLabelAlbumtitle:_albumCoverModel.title width:ScreenWidth - kCoverTitleMargin];
    
//    if (_albumCoverModel.url) {
    [self.coverUserPhoto sd_setImageWithURL:[NSURL URLWithString:DGCurrentAccount.profiles.avatarURLString]];
//    }else{
//        self.coverUserPhoto.image = [UIImage imageNamed:@"icon-person-150"];
//    }
//    self.coverUserPhoto.image = _albumCoverModel.userIcon;

    PPAccountProfiles *profiles = [PPAccountManager sharedInstance].account.profiles;
    self.coverNickNameLabel.text = profiles.name;
    
    [self addSubview:self.coverTitleLabel];
    [self addSubview:self.coverNickNameLabel];
    
    
}

+ (instancetype)photoViewWithCoverImage:(UIImage *)cover text:(NSString *)text{

    //相册描述
    PPPhoto *photo = [[PPPhoto alloc] init];
    photo.coverImage = cover;
    photo.desc = text;
    return photo;
}

+ (instancetype)photoViewWithText:(NSString *)text{

    return [self photoViewWithCoverImage:nil text:text];
}

+ (instancetype)photoViewWithCover:(UIImage *)cover{
    return [self photoViewWithCoverImage:cover text:nil];
}

//底图处理
- (void)setCoverLastImage:(UIImage *)coverLastImage{
    if (self.lastStyle == PPPhotoLastCoverSytleNone) {
        self.clipsToBounds = NO;
        self.contentMode = UIViewContentModeScaleAspectFill;
        self.image = coverLastImage;
        [self addSubview:self.coverView];
        self.codeImg.contentMode = UIViewContentModeScaleAspectFit;
        [self.coverView addSubview:self.codeImg];
//        [self.coverView addSubview:self.codeDesc];
    }else{
        self.clipsToBounds = NO;
        self.contentMode = UIViewContentModeScaleAspectFill;
        self.codeImg.contentMode = UIViewContentModeScaleAspectFit;
        self.image = coverLastImage;
        [self addSubview:self.codeImg];
//        [self addSubview:self.codeDesc];
        
    }
}


///MARK:封面处理
- (void)setCoverFrame:(PPTemplateCoverFrame *)coverFrame{

    _coverFrame = coverFrame;
    self.clipsToBounds = NO;
    self.contentMode = UIViewContentModeScaleAspectFill;
    
    //封面相框
//    if (_coverFrame.coverModel.photoFrameImage) {
//        self.image = _coverFrame.coverModel.photoFrameImage;
//    }else{
//        [self sd_setImageWithURL:[NSURL URLWithString:_coverFrame.coverModel.url]];
//    }
    NSData *coverImgdata = [[NSData alloc] initWithBase64EncodedString:_coverFrame.coverImgString options:NSDataBase64DecodingIgnoreUnknownCharacters];
    
    self.image = [UIImage imageWithData:coverImgdata];
    
    [self addSubview:self.albumScrollView];
    
    if (!self.isEditPhoto) {
        
        [self.layer addSublayer:self.shapeCoverLayer];
        self.isEditPhoto = YES;
    }
    
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.recCoverPath removeAllPoints];
        [self.shapeCoverLayer removeFromSuperlayer];
    });
    

    self.albumScrollView.coverF = _coverFrame;
    
    [self setupCoverWith:_coverFrame];

}

///MARK:描述处理 - 电子书相册描述
- (void)setDescModel:(PPTemplateDescModel *)descModel{
    
    _descModel = descModel;
    
    [self.descLabel removeFromSuperview];
    
    if (_descModel.textColor) {
        self.descLabel.textColor = [UIColor colorWithHexString:_descModel.textColor];
    }

    
    UIFont *descFont;
    
    
    CGFloat descLinespace;
    if ([NSString isFontDownloaded:_descModel.describeScript]) {
        descFont =PPFONT(_descModel.describeScript, _descModel.textFont);
        if (descModel.orderNum == 4 || descModel.orderNum == 5) {
            descLinespace = (_descModel.textMargin - _descModel.textFont);
        }else{
            descLinespace = (_descModel.textMargin - _descModel.textFont)/2 - kLabelMargin;
        }
        
    }else{
        if (_descModel.textFont > 0) {
            descFont = PPFONTSIZE(_descModel.textFont);
        }else{
            descFont = PPFONTSIZE(15);
        }
        
        descLinespace = (_descModel.textMargin - _descModel.textFont)/2 - kLabelMargin;
        if (descLinespace <= 0) {
            descLinespace = kNormalDescLineDistance;
        }

    }
//two
    if ([self.descModel.series isEqualToString:@"wave"]){
        PPLog(@"傻逼的第2个描述");
        self.descLabel.numberOfLines = 0;
       [self.descLabel changeLineSpaceForLabelWithSpace:3 text:self.desc labelFont:descFont];
        self.descLabel.insets = UIEdgeInsetsMake(5, 5, 5, 5);
        
    }else{
        
        [self.descLabel changeLineSpaceForLabelWithSpace:descLinespace text:self.desc labelFont:descFont];
    
        [self.descLabel textLabelAlbumtitle:self.desc width:ScreenWidth-2*kNormalDescMargin ];
        
    }


    self.backgroundColor = WHITE;

    [self addSubview:self.descLabel];
    
    if ([self.descModel.series isEqualToString:@"wave"]) {
    
        [self sd_setImageWithURL:[NSURL URLWithString:descModel.url11]];
        
        if (self.descModel.orderNum == 6) {
            
            self.descLabel.backgroundColor = WHITE;
             self.descLabel.layer.borderColor= COLORA(255, 1, 20).CGColor;
            
        }else if (self.descModel.orderNum == 7){
        
            self.descLabel.backgroundColor = WHITE;
            self.descLabel.layer.borderColor= COLORA(8, 0, 255).CGColor;
            self.descLabel.backgroundColor = BLACK;
//            if (self.descModel.textBorder) {
//                self.descLabel.layer.borderColor= [UIColor colorWithHexString:self.descModel.textBorder].CGColor;
//
//            }
        }
        
        self.descLabel.layer.borderWidth = self.descModel.textBorderRadius*0.1;
        self.descLabel.layer.cornerRadius = 5;
//        self.descModel.textBorderRadius*0.6;
    }
    
    

//    if ([NSString isFontDownloaded:_descModel.describeScript]) {
//        self.descLabel.font =PPFONT(_descModel.describeScript, [_descModel.textFont integerValue]);
//        //字间距
//        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:self.descLabel.text];
//        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
//        
//        [paragraphStyle setLineSpacing:_descModel.textMargin];//调整行间距
//        
//        [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [self.descLabel.text length])];
//        
//        CGFloat orgWidth = [self rectWidthWithText:self.descLabel.text height:21 font:self.descLabel.font];
//        
//        if (orgWidth > ScreenWidth - kNormalDescMargin*2) {
//            paragraphStyle.alignment = NSTextAlignmentLeft;
//        }else{
//            paragraphStyle.alignment = NSTextAlignmentCenter;
//        }
//        self.descLabel.attributedText = attributedString;
//    }else{
//        self.innerDescTextV.font = [UIFont systemFontOfSize:[_descModel.textFont floatValue]];
//        //字间距
//        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:self.innerDescTextV.text];
//        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
//        
//        [paragraphStyle setLineSpacing:_descModel.textMargin];//调整行间距
//        
//        [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [self.innerDescTextV.text length])];
//        
//        self.innerDescTextV.attributedText = attributedString;
//    }
//    
//
//    
//    self.backgroundColor = WHITE;
//
//    
//    [self addSubview:self.descLabel];
}


///MARK:电子书 内页描述
- (void)setInnerModel:(PPTemplateInnerModel *)innerModel{

    _innerModel = innerModel;
    
    self.innerScrollView.innerModel = innerModel;
    self.innerBgView.backgroundColor = WHITE;
    
    self.innerDescTextV.text = innerModel.desc;
    self.innerDescTextV.textAlignment = NSTextAlignmentCenter;
    if ([NSString isFontDownloaded:self.innerModel.describeScript]) {
        self.innerPageLabel.font = PPFONT(_innerModel.describeScript, [innerModel.pageFont floatValue]);
    }else{
         self.innerPageLabel.font = PPFONTSIZE([innerModel.pageFont floatValue]);
    }

    
    [self descTextViewText:innerModel.desc isEdit:NO];
    

    self.currentDesc = innerModel.desc;
    
   
    
    
    if (self.innerModel.pageColor) {
        self.innerPageLabel.textColor = [UIColor colorWithHexString:self.innerModel.pageColor];
    }
    self.innerPageLabel.text = [NSString stringWithFormat:@"%zd/%zd",self.innerModel.page,self.innerModel.totalPage];
    
    [self addSubview:self.innerBgView];
    [self.innerBgView addSubview:self.innerDescTextV];
    
    [self.innerBgView addSubview:self.innerPageLabel];
    [self.innerBgView addSubview:self.innerScrollView];
    
//    [self.layer addSublayer:self.shapeLayer];
    
    
    CGFloat h =  44;
    if (innerModel.desc.length > 0) {
        self.editView.eidtTextView.text = innerModel.desc;
        h = [self heightForString:self.editView.eidtTextView andWidth:SCREEN_WIDTH];
    }
    self.editView.frame = CGRectMake(0,SCREEN_HEIGHT, SCREEN_WIDTH, h);
    
    [self.innerBgView addSubview:self.editView];
    
    if ([innerModel.series isEqualToString:@"wave"]) {
        [self.innerBgView sd_setImageWithURL:[NSURL URLWithString:innerModel.url11]];
    }
}
- (void)setTotalPage:(NSInteger)totalPage{

//    self.innerPageLabel.text = [NSString stringWithFormat:@"%@%zd",self.innerPageLabel.text,totalPage];
}


#pragma mark - 描述处理
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    if ([text isEqualToString:@"\n"]){
        
        if (textView.text.charCount <= kDescMaxSize) {
            
            self.isEditDesc = YES;
        }        
        
        [[UIApplication sharedApplication].keyWindow endEditing:YES];
        
        return NO;
    }
    
    return YES;
}
//MARK:键盘
- (void)keyBoardWasShow:(NSNotification *)notice{
    NSDictionary *dict=notice.userInfo;
    //获取时间
    self.time = [dict[UIKeyboardAnimationDurationUserInfoKey] floatValue];
    //动画曲线
    self.curve = [dict[UIKeyboardAnimationCurveUserInfoKey] integerValue];
    //键盘高度
    self.keyboardHeight = [dict[UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height;
    
    [UIView animateWithDuration:self.time animations:^{
        //曲线
        [UIView setAnimationCurve:self.curve];
        CGRect editF = self.editView.frame;
        editF.origin.y = SCREEN_HEIGHT - self.keyboardHeight - 64 - self.editView.frame.size.height;
        self.editView.frame = editF;
    }];
}
- (void)keyboardWillBeHidden:(NSNotification *)notice{
    
    self.innerScrollView.userInteractionEnabled = YES;
    
    [UIView animateWithDuration:self.time animations:^{
        //曲线
        [UIView animateWithDuration:self.time animations:^{
            //曲线
            [UIView setAnimationCurve:self.curve];
            CGRect editF = self.editView.frame;
            editF.origin.y = SCREEN_HEIGHT;
            self.editView.frame = editF;
        }];
        
//        if (self.editView.eidtTextView.text) {
//            [self descTextViewText:self.editView.eidtTextView.text];
//            
//            
//            [self updateDesc:self.editView.eidtTextView.text];
//        }
    }];
}
- (void)textViewDidEndEditing:(UITextView *)textView{
    
    if (self.isEditTitle) {
        [self changeAlbumTitle:textView.text];
        return;
    }
    if (self.isEditDesc) {
        [self descTextViewText:self.editView.eidtTextView.text isEdit:YES];
        [self updateDesc:textView.text];
        
        self.innerScrollView.userInteractionEnabled = YES;
    }
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{

    self.isEditDesc = NO;
    
    if (textView == self.innerDescTextV) {
        
        [self.editView.eidtTextView  becomeFirstResponder];

        return NO;
    }
    return YES;
    
}

- (void)textViewDidChange:(UITextView *)textView{
    
    CGSize contentSize = self.editView.eidtTextView.contentSize;

    CGRect f = self.editView.frame;
    f.origin.y = SCREEN_HEIGHT - 64 - self.keyboardHeight - contentSize.height - 10;
    f.size.height = contentSize.height + 10;
    self.editView.frame = f;

    CGRect tF = self.editView.eidtTextView.frame;
    tF.size.height = contentSize.height;
    self.editView.eidtTextView.frame = tF;
    PPLog(@"%@",textView.text);
    if (textView.text.charCount > kDescMaxSize) {
        [self toastMessage:[NSString stringWithFormat:@"最多%zd字",kDescMaxSize]];
    }
}
- (float) heightForString:(UITextView *)textView andWidth:(float)width{
    CGSize sizeToFit = [textView sizeThatFits:CGSizeMake(width, MAXFLOAT)];
    return sizeToFit.height;
}

- (void)descTextViewText:(NSString *)text isEdit:(BOOL)isEdit{
    
    NSString *desc = text;
//    NSInteger index = 0;
    NSDictionary *attributes;
    if (desc.length <= 0 && isEdit) {
        desc = @" 添加描述";
        attributes = @{NSFontAttributeName:PPFONTSIZE(15),NSForegroundColorAttributeName:[UIColor lightGrayColor]};

    }else{
        
        if (self.innerModel.describeColor) {
            self.innerDescTextV.textColor = [UIColor colorWithHexString:self.innerModel.describeColor];
        }

        
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
        
        if (self.innerModel.orderNum == 3) {
            paragraphStyle.alignment = NSTextAlignmentCenter;
        }else{
            paragraphStyle.alignment = NSTextAlignmentLeft;
        }

        UIFont *descFont;
        if ([NSString isFontDownloaded:self.innerModel.describeScript]) {
            descFont = PPFONT(_innerModel.describeScript, self.innerModel.describeFont);
            
            if (_innerModel.orderNum == 4 || _innerModel.orderNum == 5) {
                
                paragraphStyle.lineSpacing = (self.innerModel.describeMargin - self.innerModel.describeFont);
                paragraphStyle.maximumLineHeight = 8.f;
                paragraphStyle.minimumLineHeight = 8.f;
            }else{
            
               paragraphStyle.lineSpacing = (self.innerModel.describeMargin - self.innerModel.describeFont)/2 - kLabelMargin;
                
            }
            
        }else{
            descFont = [UIFont systemFontOfSize:self.innerModel.describeFont];
            
            paragraphStyle.lineSpacing = (self.innerModel.describeMargin - self.innerModel.describeFont)/2;
        }
        
        if (self.innerDescTextV.font && self.innerDescTextV.textColor) {
            attributes = @{NSFontAttributeName:descFont,NSForegroundColorAttributeName:self.innerDescTextV.textColor,NSParagraphStyleAttributeName:paragraphStyle};
        }

    }
     NSInteger index = desc.length;
    
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ ",desc?desc:@""] attributes:attributes];
   
    if (isEdit) {
        NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithData:nil ofType:nil] ;
//        textAttachment.image = [UIImage imageNamed:@"ebook_desc"];
        
        textAttachment.image = [UIImage imageNamed:@"icon_pen"];
        textAttachment.bounds = CGRectMake(0, -2.4, textAttachment.image.size.width*0.40, textAttachment.image.size.height*0.40);
        
        NSAttributedString *textAttachmentString = [NSAttributedString attributedStringWithAttachment:textAttachment];
        [string insertAttributedString:textAttachmentString atIndex:index];//index为用户指定要插入图片的位置
        
    }
//    self.innerDescTextV.backgroundColor = RED;
    self.innerDescTextV.attributedText = string;
    
    
    if ([self.innerModel.series isEqualToString:@"wave"]) {
         self.innerDescTextV.textAlignment = NSTextAlignmentCenter;
        if (self.innerModel.orderNum == 7) {
            self.innerDescTextV.backgroundColor = BLACK;
             self.innerDescTextV.layer.borderColor= COLORA(8, 0, 255).CGColor;
//            if (self.innerModel.textBorder) {
//               self.innerDescTextV.layer.borderColor= [UIColor colorWithHexString:self.innerModel.textBorder].CGColor;
//            }
        }else{
             self.innerDescTextV.layer.borderColor= COLORA(255, 1, 20).CGColor;
            //        if (self.innerModel.textBorder) {
            //           self.innerDescTextV.layer.borderColor= [UIColor colorWithHexString:self.innerModel.textBorder].CGColor;
            //        }
     
        }
        
         self.innerDescTextV.layer.borderWidth = self.innerModel.textBorderRadius*0.1;
        self.innerDescTextV.layer.cornerRadius = 5;
//        self.innerModel.textBorderRadius*0.4;
        
        
        if (desc.length<=0) {
            NSString *tempDesc = text;
            tempDesc = @" 添加描述";
            NSDictionary *tempTtributes = @{NSFontAttributeName:PPFONTSIZE(15),NSForegroundColorAttributeName:[UIColor lightGrayColor]};
            NSInteger index = tempDesc.length;
            
            NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ ",tempDesc?tempDesc:@""] attributes:tempTtributes];
            
                NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithData:nil ofType:nil] ;

            textAttachment.image = [UIImage imageNamed:self.innerModel.orderNum == 7?@"icon_pen_wave":@"icon_pen"];
                textAttachment.bounds = CGRectMake(0, -2.4, textAttachment.image.size.width*0.40, textAttachment.image.size.height*0.40);
                
            NSAttributedString *textAttachmentString = [NSAttributedString attributedStringWithAttachment:textAttachment];
            [string insertAttributedString:textAttachmentString atIndex:index];//
            
            self.innerDescTextV.attributedText = string;

        }
        
    }
    
}

///MARK: 更新描述
- (void)updateDesc:(NSString *)changeDesc{
    

    
//    NSRange startRange = [self.innerPageLabel.text rangeOfString:@"/"];
//    
//    NSRange range = NSMakeRange(0,startRange.location + startRange.length);
//    NSString *result = [self.innerPageLabel.text substringWithRange:range];
    NSArray *array = [self.innerPageLabel.text componentsSeparatedByString:@"/"];
    PPTemplateInnerModel *innerModel = self.innerModel;
    
    innerModel.picModel = self.pics[[[array firstObject] integerValue] - 1];
    
//    PPLog(@"修改了第几个 %zd",[result integerValue]);
    if (self.style == PPPhotoCoverSytleNone) {
        
//                NSInteger index = [[self.innerPageLabel.text substringToIndex:1] integerValue];
//                if (index > self.innerModel.sortedImages.count) {
//                    return;
//                }
//        self.currentDesc = changeDesc;
//                    PPAlbumImageModel *obj = self.innerModel.sortedImages[index-1];
//                    PPAbstractArtwork *artwork = obj.artwork;
//                    artwork.desc = changeDesc.length>0?changeDesc:@"";
//                    artwork.modified = @(YES);
//                    [[PPAlbumManager sharedInstance] offlineModifyAlbumWithAlbumUUID:self.innerModel.albumUUID insertedArtworks:nil modifiedArtworks:@[artwork] deletedArtworks:nil tags:nil title:nil description:nil order:nil permission:nil privacy:nil privacyUserIDs:nil coverUUID:nil];
    }else{
    
         self.currentDesc = changeDesc;
        
//        PPHomeEbookModel *ebookM = self.innerModel.sortedImages[[result integerValue]-1];

        
//        NSDictionary *dict = @{
//                               @"user":@([DGCurrentAccount.userID longLongValue]),
//                               @"albumid":ebookM.albumId?ebookM.albumId:self.innerModel.albumId,
//                               @"pictureid":ebookM.pictureId,
//                               @"description":self.currentDesc
//                               };
        NSDictionary *dict = @{
                               @"user":@([DGCurrentAccount.userID longLongValue]),
                               @"albumid":innerModel.picModel.albumID,
                               @"pictureid":innerModel.picModel.picID,
                               @"description":self.currentDesc
                               };
        [PPNetworkService updatePictureDescWithParams:dict callback:^(id data, NSError *error) {
            
            if(error == nil) {
                
                [self picAlbumDic:dict];
                
                [[NSNotificationCenter defaultCenter] postNotificationName:PPNotice_ChangeAlbumsDesc object:@{@"pictureid":dict[@"pictureid"],@"description":dict[@"description"]}];  
            }
        }];
    }
    
    if(self.innerModel.orderNum == 3) {
        
        CGRect rectDesc = self.innerDescTextV.frame;
        CGFloat descY = self.innerModel.describeYaxis -64;
        
        CGFloat descHeight = [self heightForString:self.innerDescTextV andWidth:self.innerModel.describeWidth];
        
            if ((self.innerModel.frameYaxis - 64 - descHeight) > 0) {
                descY = (self.innerModel.frameYaxis - 64 - descHeight)/2;
            }
        rectDesc.origin.y = descY;
        self.innerDescTextV.frame = rectDesc;
    }

}
///同步到本地
- (void)picAlbumDic:(NSDictionary *)dict{

    if (!self.innerModel.picModel.picAuuid) {
        return;
    }
    
    NSArray <PPAlbumImageModel *> *images = [PPAlbumImageModel where:@{@"auuid" : self.innerModel.picModel.picAuuid}];
    
    NSMutableArray <PPAlbumImageModel *> *modifiedPictures = [NSMutableArray array];
    for(PPAlbumImageModel *image in images) {
        [modifiedPictures addSafeObject:image];
    }
    [modifiedPictures enumerateObjectsUsingBlock:^(PPAlbumImageModel *_Nonnull obj, NSUInteger idx, BOOL *_Nonnull stop) {
        NSManagedObjectID *objectID = obj.objectID;
        NSString *picId = [NSString stringWithFormat:@"%@",obj.imageID];
        if ([picId isEqualToString:[NSString stringWithFormat:@"%@",dict[@"pictureid"]]]) {
            obj.desc = dict[@"description"];
            PPAlbumImageModel *image = [[NSManagedObjectContext threadObjectContext] objectWithID:objectID];
            image.modified = @(NO);
            [image.managedObjectContext saveContext];
        }
    }];
}
- (void)hiddenKeyboard{

    [[UIApplication sharedApplication].keyWindow endEditing:YES];
}


#pragma mark - 电子书封面标题、用户
- (void)setupCoverWith:(PPTemplateCoverFrame *)coverFrame{
    self.albumTitleL.userInteractionEnabled = YES;
    if (coverFrame.orderNum == 1||coverFrame.orderNum == 2||coverFrame.orderNum == 4) {
        self.albumTitleL.numberOfLines = 0;
        self.albumTitleL.textAlignment = NSTextAlignmentLeft;
        self.coverNickNameLabel.textAlignment = NSTextAlignmentLeft;
    }else{
        self.albumTitleL.textAlignment = NSTextAlignmentCenter;
        self.coverNickNameLabel.textAlignment = NSTextAlignmentCenter;
    }

    if (_coverFrame.titleColor) {
        self.albumTitleL.textColor =  [UIColor colorWithHexString:_coverFrame.titleColor];
    }
    
    
    UIFont *titlefont;
    if ([NSString isFontDownloaded:_coverFrame.titlePostScript]) {
        titlefont = PPFONT(_coverFrame.titlePostScript, [_coverFrame.titleFont integerValue]);
        if ([coverFrame.titlePostScript isEqualToString:@"PingFang SC"]) {
            titlefont = PPFONTSIZE([_coverFrame.titleFont integerValue]);
        }
        
    }else{
        titlefont = PPFONTSIZE([_coverFrame.titleFont integerValue]);
    }
    
    
    if (coverFrame.orderNum == 2 || coverFrame.orderNum == 3) {
        titlefont = PFFontBold([_coverFrame.titleFont integerValue]);
    }
    
    if (coverFrame.orderNum == 4 || coverFrame.orderNum == 5) {
        
                _albumTitleL.layer.shadowColor = [UIColor colorWithHexString:@"0X000000"].CGColor;//阴影颜色
                _albumTitleL.layer.shadowOffset = CGSizeMake(-0.5, -0.5);//偏移距离
                _albumTitleL.layer.shadowOpacity = 0.5;//不透明度
                _albumTitleL.layer.shadowRadius = 1;//半径
        

        
        if (coverFrame.orderNum == 4) {
            self.albumTitleL.textColor =  [UIColor colorWithHexString:@"#FFFFFF"];
            titlefont = PFFontBold([_coverFrame.titleFont integerValue]);

        }
        
    }


    CGFloat lineSpace = (_coverFrame.titleMargin - [_coverFrame.titleFont integerValue])/2-kLabelMargin;
    if (coverFrame.orderNum == 2 || coverFrame.orderNum == 3 || coverFrame.orderNum == 4 ||coverFrame.orderNum == 5) {
        lineSpace = 8/2;
        
        if (coverFrame.orderNum == 4 || coverFrame.orderNum == 5) {
            lineSpace = 8/2-kLabelMargin*2;
        }
    }
    
    [self.albumTitleL changeLineSpaceForLabelWithSpace:lineSpace text:_coverFrame.coverModel.title labelFont:titlefont];
    

    if (coverFrame.orderNum == 3 || coverFrame.orderNum == 5 || coverFrame.orderNum == 6 || coverFrame.orderNum == 7) {
        self.albumTitleL.textAlignment = NSTextAlignmentCenter;
    }


    if ([NSString isFontDownloaded:_coverFrame.titlePostScript]) {
        self.coverNickNameLabel.font = PPFONT(_coverFrame.titlePostScript, [_coverFrame.userFont integerValue]);
    }else{
        self.coverNickNameLabel.font = PPFONTSIZE([_coverFrame.userFont integerValue]);
    }
    
    if (_coverFrame.userColor) {
        self.coverNickNameLabel.textColor = [UIColor colorWithHexString:_coverFrame.userColor];
    }
    
    if (coverFrame.orderNum == 4 || coverFrame.orderNum == 5) {
        if (coverFrame.orderNum == 4) {
            self.coverNickNameLabel.textColor =  [UIColor colorWithHexString:@"#FFFFFF"];
            self.coverNickNameLabel.font = PFFontBold([_coverFrame.userFont integerValue]);
        }
        
        self.coverNickNameLabel.layer.shadowColor = [UIColor colorWithHexString:@"#000000"].CGColor;//阴影颜色
        self.coverNickNameLabel.layer.shadowOffset = CGSizeMake(-0.5, -0.5);//偏移距离
        self.coverNickNameLabel.layer.shadowOpacity = 0.5;//不透明度
        self.coverNickNameLabel.layer.shadowRadius = 1.0;//半径
    }
    
    //用户名
    PPAccountProfiles *profiles = [PPAccountManager sharedInstance].account.profiles;
    self.coverNickNameLabel.text = profiles.name;
//    self.coverNickNameLabel.text = _coverFrame.coverModel.nickName;
    
    if (coverFrame.orderNum == 6|| coverFrame.orderNum == 7) {
        self.coverNickNameLabel.font = [UIFont boldSystemFontOfSize:[_coverFrame.userFont doubleValue]];
       self.albumTitleL.font = [UIFont boldSystemFontOfSize:[_coverFrame.titleFont doubleValue]];
        
        self.albumTitleL.textAlignment = NSTextAlignmentCenter;
    }
    if (coverFrame.orderNum == 2 || coverFrame.orderNum == 3) {
        self.albumTitleL.font = PFFontBold([_coverFrame.titleFont doubleValue]);
    }
    [self addSubview:self.albumTitleL];
    [self addSubview:self.coverNickNameLabel];
    

   
    CGFloat h =  44;
        self.editView.eidtTextView.text = self.albumTitleL.text;
        h = [self heightForString:self.editView.eidtTextView andWidth:SCREEN_WIDTH];

    self.editView.frame = CGRectMake(0,SCREEN_HEIGHT, SCREEN_WIDTH, h);
    
    [self addSubview:self.editView];
    
    
//    if (self.shapeTitleLayer == nil) {
    if (!self.isFirstGoto) {
//        [self.layer addSublayer:self.shapeTitleLayer]; 删除
        self.isFirstGoto = YES;
    }

//    }
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2* NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.shapeTitleLayer removeFromSuperlayer];
    });
}

#pragma mark - 调整封面相框位置
- (void)adjustCoverViewFrame:(PPTemplateCoverFrame *)coverFrame{

    CGFloat boxY = coverFrame.boxYaxis - 64;
    CGFloat boxH = coverFrame.boxHeight;

    switch (coverFrame.orderNum) {
        case 1:
        {
            boxY = coverFrame.boxYaxis - 64 + 2;
            
        }
            break;
        case 2:
        {
            boxY = coverFrame.boxYaxis - 64 + 2;
            
        }
            break;
            
        default:
            break;
    }
    
    
    
    if ([self.innerModel.series isEqualToString:@"wave"]) {
        boxH = coverFrame.boxWidth;
    }
    
    self.albumScrollView.frame = CGRectMake(coverFrame.boxXaxis, boxY,coverFrame.boxWidth, boxH);
//    if (!self.isEditPhoto) {
        self.shapeCoverLayer.frame = self.albumScrollView.frame;
//        self.isEditPhoto = YES;
//    }
    self.albumScrollView.cutRect = CGRectMake(coverFrame.boxXaxis, boxY,coverFrame.boxWidth, boxH);

}


#pragma mark - 调整封面标题位置
- (void)adjustCoverTitleViewFrame:(PPTemplateCoverFrame *)coverFrame{
    
    
//    self.albumTitleL.backgroundColor = RED;
    CGFloat coverTitleY = coverFrame.titleYaxis - 64;
    
    CGFloat coverTitleHeight =  coverFrame.titleHeight;
    
    CGFloat coverTitleX = coverFrame.titleXaxis;
    CGFloat layerTitleY = coverFrame.titleYaxis - 64;
     CGFloat layerTitleH = 0;
    PPLog(@"----是%zd",coverFrame.orderNum);
    if ([self.albumTitleL labelText:self.albumTitleL.text width:coverFrame.titleWidth]) {
        //大于一行
        switch (coverFrame.orderNum) {
            case 1:
            {
                coverTitleHeight = 66;
                coverTitleY =  coverFrame.titleYaxis - 64;
                if (IS_IPHONE_6_PLUS) {
                     coverTitleY = coverFrame.titleYaxis - 64 ;   
                }
                
//                if (IS_IPHONE_6) {
                    layerTitleY = coverFrame.titleYaxis - 64 - 15;
//                }
            }
                break;
            case 2:
            {
                coverTitleY = coverFrame.titleYaxis - 64 + 6;
                if (IS_IPHONE_6_PLUS) {
                    coverTitleY = coverFrame.titleYaxis - 64  + 9 - kLabelMargin;
                }
//                if (IS_IPHONE_6) {
                    layerTitleY = coverFrame.titleYaxis - 64 - 15 - 15;
//                }
            }
                break;
            case 3:
            {
                coverTitleY = coverFrame.titleYaxis - 64 + 2 - 12 - 8;
                
                if (IS_IPHONE_6) {
                    layerTitleY = coverFrame.titleYaxis - 64 + 2 - 12 - 8 - 15;
                }
                if (IS_IPHONE_6_PLUS) {
                    layerTitleY = coverFrame.titleYaxis - 64 + 2 - 12 - 8 - 23;
                }
                
            }
                break;
            case 4:
            {   //设计、生活
                coverTitleY = coverFrame.titleYaxis - 64 + 9 - 14;
                coverTitleHeight =  coverFrame.titleHeight + 10;
                if (IS_IPHONE_6_PLUS) {
                    coverTitleY = coverFrame.titleYaxis - 64 + 9 - 14 - 24;
                    
                    layerTitleY = coverFrame.titleYaxis - 64 + 9 - 14 - 24;
                }
                if (IS_IPHONE_6) {
                    layerTitleY = coverFrame.titleYaxis - 64 + 9 - 14 - 15;
                }
            }
                break;
                
            case 5:
            {
                coverTitleY =  coverFrame.titleYaxis - 64 - 5;
                coverTitleHeight =  coverFrame.titleHeight + 20;
                
//                if (IS_IPHONE_6) {
                    layerTitleY = coverFrame.titleYaxis - 64 - 5 - 25;
//                }
            }
                break;
            case 6:
            {
                coverTitleX = (ScreenWidth - coverFrame.titleWidth)/2;
                coverTitleY =  coverFrame.titleYaxis - 64 - 35;

                
                if (IS_IPHONE_6_PLUS) {
                    coverTitleY =  coverFrame.titleYaxis - 64 - 8;
                    layerTitleY = coverFrame.titleYaxis - 64 - 8 - 7;
                }
                
                if (IS_IPHONE_6) {
                     coverTitleY =  coverFrame.titleYaxis - 64 - 50;
                }
                
                
                coverTitleHeight =  coverFrame.titleHeight + 20 + 46;
                
                
            }
                break;
            case 7:
            {
                coverTitleY =  coverFrame.titleYaxis - 64 - 5 - 10 - 30;
                coverTitleHeight =  coverFrame.titleHeight + 20 + 46;
                if (IS_IPHONE_6) {
                         coverTitleY =  coverFrame.titleYaxis - 64 - 5 - 10 ;
                }
                if (IS_IPHONE_6_PLUS) {
                    coverTitleY =  coverFrame.titleYaxis - 64 - 8 - 10;
                    layerTitleY = coverFrame.titleYaxis - 64 - 8 - 13;
                }
            }
                break;
                
            default:
                break;
        }
        
        
    }else{
        switch (coverFrame.orderNum) {
            case 1:
            {
                coverTitleHeight = 25;
                coverTitleY = coverFrame.titleYaxis - 64 + 13;
                if (IS_IPHONE_6_PLUS) {
                    coverTitleY = coverFrame.titleYaxis - 64 + 3;  
                }
                
            }
                break;
            case 2:
            {
                coverTitleY = coverFrame.titleYaxis - 64 + 6;
                if (IS_IPHONE_6_PLUS) {
                    coverTitleY = coverFrame.titleYaxis - 64  + 9 - kLabelMargin;
                    layerTitleY = coverFrame.titleYaxis - 64  + 9 - kLabelMargin  +2;
                }
                if (IS_IPHONE_6) {
                    layerTitleY = coverFrame.titleYaxis - 64 + 6 - 1;
                }
            }
                break;
            case 3:
            {
                coverTitleY = coverFrame.titleYaxis - 64 + 2 -12-8 ;
                
//                if (IS_IPHONE_6) {
                    layerTitleY = coverFrame.titleYaxis - 64 + 2 -12-8 -5;
//                }
            }
                break;
            case 4:
            {   //设计、生活
                coverTitleY = coverFrame.titleYaxis - 64 + 9 - 14;
                if (IS_IPHONE_6_PLUS) {
                    coverTitleY = coverFrame.titleYaxis - 64 + 9 - 14 - 24;
                    
                    layerTitleY = coverFrame.titleYaxis - 64 + 9 - 14 - 24 - 4;
                }
            }
                break;
            case 5:
            {
                if (IS_IPHONE_6_PLUS) {
                    layerTitleY = coverFrame.titleYaxis - 64 + 2;
                }else{
                    coverTitleY = coverFrame.titleYaxis - 64 + 3;
                    
                }
                
                if (IS_IPHONE_6) {
                    layerTitleY = coverFrame.titleYaxis - 64 + 3 + 1;
                }
                
            }
                break;
            case 6:
            {
               coverTitleX = (ScreenWidth - coverFrame.titleWidth)/2;
                if (IS_IPHONE_6_PLUS) {
                    coverTitleY =  coverFrame.titleYaxis - 16;
                    layerTitleY = coverFrame.titleYaxis - 16;
                }else{
                    coverTitleY = coverFrame.titleYaxis - 64 + 3;
                    
                    
                    
                    if (IS_IPHONE_6) {
                        coverTitleY =  coverFrame.titleYaxis - 64 - 16;
                        layerTitleY = coverFrame.titleYaxis - 64 - 8 - 7 - 20;
                    }
                }
            }
                break;
            case 7:
            {
                 coverTitleY = coverFrame.titleYaxis - 64 +2;
                if (IS_IPHONE_6_PLUS) {
                   coverTitleY = coverFrame.titleYaxis - 20;
                    layerTitleY = coverFrame.titleYaxis - 20;
                }
            }
                break;
                
            default:
                break;
        }
    }
    

    self.albumTitleL.frame = CGRectMake(coverTitleX,coverTitleY, coverFrame.titleWidth,coverTitleHeight);

//    self.shapeTitleLayer.frame = CGRectMake(coverTitleX,layerTitleY >0?layerTitleY:coverTitleY, coverFrame.titleWidth,layerTitleH >0?layerTitleH:coverTitleHeight);
}
#pragma mark -调整封面用户名
- (void)adjustCoverUserLabel:(PPTemplateCoverFrame *)coverFrame{

    CGFloat userY = coverFrame.userYaxis - 64;
    
    switch (coverFrame.orderNum) {
        case 2:
        {
            userY = coverFrame.userYaxis - 64 + 2;
            if (IS_IPHONE_6_PLUS) {
                userY = coverFrame.userYaxis - 64 + 1;
            }
        }
            break;
        case 3:
        {
            if (IS_IPHONE_6_PLUS) {
                userY = coverFrame.userYaxis - 64 - 2;
            }
        }
            break;
            
        case 4:
        {
            userY = coverFrame.userYaxis - 64;
            if (IS_IPHONE_6_PLUS) {
                userY = coverFrame.userYaxis - 64 - 11;
            }

        }
            break;
        case 6:
        {
      
            userY = CGRectGetMaxY(self.albumTitleL.frame) + 10;
            
            
            if ([self.albumTitleL labelText:self.albumTitleL.text width:coverFrame.titleWidth]) {
                userY = CGRectGetMaxY(self.albumTitleL.frame);
                
                if (IS_IPHONE_6) {
//                    userY = CGRectGetMaxY(self.albumTitleL.frame) - 18;
                     userY = CGRectGetMaxY(self.albumTitleL.frame) + ([self.albumTitleL labelText:self.albumTitleL.text width:coverFrame.titleWidth]?-18:-28);
                }
                
            }
            
            
        }
            break;
        case 7:
        {
            userY = CGRectGetMaxY(self.albumTitleL.frame) + ([self.albumTitleL labelText:self.albumTitleL.text width:coverFrame.titleWidth]?0:5);
            if (IS_IPHONE_6) {
                userY = CGRectGetMaxY(self.albumTitleL.frame) + ([self.albumTitleL labelText:self.albumTitleL.text width:coverFrame.titleWidth]?-10:5);
            }
            
        }
            break;
            
        default:
            break;
    }
    

    
    self.coverNickNameLabel.frame = CGRectMake(coverFrame.userXaxis, userY , coverFrame.userWidth, coverFrame.userHeight);
}
#pragma mark -调整内页frame
- (void)adjustInnerViewFrame{

    CGFloat descX = self.innerModel.describeXaxis;
    CGFloat descY = self.innerModel.describeYaxis -64;
    CGFloat descW = self.innerModel.describeWidth;
    CGFloat descH = self.innerModel.describeHeight;
//    self.innerDescTextV.backgroundColor = RED;
    switch (self.innerModel.orderNum) {
        case 3:
        {
            CGFloat descHeight = [self heightForString:self.innerDescTextV andWidth:descW];

            if ((self.innerModel.frameYaxis - 64 - descHeight) > 0) {
                descY = (self.innerModel.frameYaxis - 64 - descHeight)/2;
            }
        }
            break;
        case 4:
        {
            self.innerDescTextV.textContainerInset = UIEdgeInsetsMake(0,0, 0,20/2+2);
            descX = 17;
//            descY = self.innerModel.describeYaxis - 64;
            descY = self.innerModel.frameYaxis + self.innerModel.frameHeight - 64 + 25 - kLabelMargin;
            descW = ScreenWidth-17;
            
//            if (IS_IPHONE_6_PLUS) {
//               descY = self.innerModel.describeYaxis - 64 + 25 - 10 + 1;
//            }
            
        }
            break;
        case 5:
        {
            ///？？？？
            self.innerDescTextV.textContainerInset = UIEdgeInsetsMake(0,0, 0,20/2+2);

            descX = 17;
            descY = self.innerModel.describeYaxis -64;
            descW = ScreenWidth-17;
//            if (IS_IPHONE_6_PLUS) {
//                descY = self.innerModel.describeYaxis - 64 + 10;
//            }
        }
            break;
        case 6:
        {
             descH = [self heightForString:self.innerDescTextV andWidth:descW];
        }
            break;
        case 7:
        {
            descH = [self heightForString:self.innerDescTextV andWidth:descW];
        }
            break;
            
        default:
            descX = 20;
            descW = ScreenWidth - 20*2;
            
            break;
    }
//    self.innerDescTextV.backgroundColor = RED;
    self.innerDescTextV.frame = CGRectMake(descX,descY,descW,descH);

    
}

#pragma mark -上传 更新内页图片
- (void)createPicpathWithuuids:(NSArray *)uuids picCutImage:(UIImage *)picCutImage picType:(NSInteger)picType{
    
    NSMutableArray *paths = [NSMutableArray array];
    
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    
    [params setSafeObject:@([DGCurrentAccount.userID longLongValue]) forKey:@"user"];
    [params setSafeObject:uuids forKey:@"pictureId"];
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self animated:YES];
    hud.mode = MBProgressHUDModeAnnularDeterminate;
    hud.labelText = @"正在上传";
    
    [PPNetworkService createEbookPicpathWithparams:params callback:^(id data, NSError *error) {
        PPLog(@"七牛path =  %@",data);
        
        NSArray *res = (NSArray *)data;
        if (res.count > 0) {
            for (int i = 0; i<res.count; i++) {
                PPUploaderFile *uploadFile = [PPUploaderFile yy_modelWithDictionary:res[i]];
                uploadFile.image = picCutImage;
                [paths addObject:uploadFile];
            }
        }
        
        if (paths.count > 0) {
            //    3.回调获取七牛路径 上传图片到七牛
 
            PPUploaderFile *file = [paths firstObject];
            PPUploadPicture *picture = [[PPUploadPicture alloc] init];
            picture.image = file.image;
            picture.key = file.path;
            picture.token = file.uploadToken;

            [[PPCommonPicturesUploaderManager sharedInstance] uploadPicture:picture completion:^(id data, NSError *error) {
                 PPLog(@"上传进度 = --- %@ - error =%@",data,error);
                if (error == nil) {
                    hud.labelText = @"上传成功 ";
                    NSMutableArray *pictures = [NSMutableArray array];
                     NSMutableDictionary *dictPic = [NSMutableDictionary dictionary];
                    [dictPic setSafeObject:uuids.firstObject forKey:@"pictureId"];
                    [dictPic setSafeObject:@(3) forKey:@"operateType"];
                    [dictPic setSafeObject:@(picType) forKey:@"picType"];
                    [dictPic setSafeObject:picture.key forKey:@"url"];
                    [pictures addObject:dictPic];
                    
                    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
                    
                    [dict setSafeObject:picType==2?self.innerModel.picModel.albumID:self.coverFrame.coverModel.albumID forKey:@"albumId"];
                    [dict setSafeObject:pictures forKey:@"pics"];
                    [PPNetworkService updateAlbumeBookWithParams:dict callback:^(id data, NSError *error1) {
                        if (error1 == nil) {
                            PPLog(@"更新成功");
                            
                            NSMutableDictionary *updatePic = [NSMutableDictionary dictionary];
                            [updatePic setSafeObject:uuids.firstObject forKey:@"pictureid"];
                            [updatePic setSafeObject:@(picType) forKey:@"picType"];
                            [updatePic setSafeObject:file.image forKey:@"img"];
                            [updatePic setSafeObject:picture.key forKey:@"url"];
                            
                            [[NSNotificationCenter defaultCenter] postNotificationName:PPNotice_ChangeAlbumsPic object:updatePic];
                            
                            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                                
                                [hud hide:YES];
                                
                            });
                        }else{
                            PPLog(@"更新失败");
                            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                                
                                [hud hide:YES];
                                
                            });
                        }
                    }];
                }else{
                    hud.labelText = @"上传失败 ";
                    
                    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                        
                        [hud hide:YES];
                        
                    });
                }
                
//                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//                    
//                    [hud hide:YES];
//                    
//                });
                
            } progress:^(NSString *key, float percent) {
                hud.progress = percent;
            }];
        }
        
    }];
}

#pragma mark -监听编辑状态
#pragma mark -albumScrollViewdelegate
//- (void)albumImageClickView:(PPAlbumScrollView *)view scrollView:(UIScrollView *)scrollview albumView:(UIImageView *)imageView{
//
//        self.isEdit = YES;
//
//        //开启编辑
//        [self showToolBar];
//
//        if (self.innerPageLabel.text.length > 0) {
//
//            NSArray *array = [self.innerPageLabel.text componentsSeparatedByString:@"/"];
//            PPTemplateInnerModel *innerModel = self.innerModel;
//            innerModel.picModel = self.pics[[[array firstObject] integerValue] - 1];
//
//            if (innerModel.picModel.picDesc.length <= 0) {
//                [self startEdit:nil];
//            }
//
//        }
//
//}
- (void)albumImageBeginEditorView:(PPAlbumScrollView *)view{

    [self showToolBar];

    if (self.BlockStartEdit) {
        self.BlockStartEdit();
    }

    if (self.innerPageLabel.text.length > 0) {

        NSArray *array = [self.innerPageLabel.text componentsSeparatedByString:@"/"];
//        PPTemplateInnerModel *innerModel = self.innerModel;
        self.innerModel.picModel = self.pics[[[array firstObject] integerValue] - 1];

        if (self.innerModel.picModel.picDesc.length <= 0) {
            [self startEdit:nil];
        }

    }

}

-(void)albumImageEndEditorView:(PPAlbumScrollView *)view{

    [self hiddenToolBar];

    if (self.BlockAccomplishEdit) {
        self.BlockAccomplishEdit();
    }

}

#pragma mark -toolBar
- (PPToolBarView *)toolBar{

    if (!_toolBar) {
        _toolBar = [PPToolBarView toolBarView];
        _toolBar.backgroundColor = WHITE;
        _toolBar.alpha = 0.9;
        _toolBar.delegate = self;
    }
    return _toolBar;
}
- (void)toolBarView:(PPToolBarView *)toolBar didSelect:(NSInteger)select{
    //修改内页

    
    if (self.picType == 1) {
        [self.albumScrollView cancelEdit];
        [self.innerScrollView cancelEdit];
        //修改封面
        if (select == 1) {
            //取消
            self.coverFrame = self.coverFrame;
            
        }else if(select == 2){
            
            NSArray *uuids = @[self.coverFrame.coverModel.CoverPicID];
              [self createPicpathWithuuids:uuids picCutImage:[self.albumScrollView cutImage] picType:1];
        }

    }else{

        [self.innerScrollView cancelEdit];
        
        NSArray *array = [self.innerPageLabel.text componentsSeparatedByString:@"/"];
        PPTemplateInnerModel *innerModel = self.innerModel;
        innerModel.picModel = self.pics[[[array firstObject] integerValue] - 1];
        if (select == 1) {
            //取消
            self.innerScrollView.innerModel = self.innerModel;
            
        }else if(select == 2){
            NSArray *uuids = @[innerModel.picModel.picID];
            [self createPicpathWithuuids:uuids picCutImage:[self.innerScrollView cutImage] picType:2];
        }
        
        if (innerModel.picModel.picDesc.length <= 0) {
            self.innerDescTextV.editable = NO;
            self.isEditAlbumImage = NO;
            [self descTextViewText:self.currentDesc isEdit:self.isEditAlbumImage];
        }
    }
    
    //完成
    [self hiddenToolBar];
    //可以滑动到下一页
    [[NSNotificationCenter defaultCenter] postNotificationName:PPNotice_isEditImage object:@(NO)];
}
- (void)showToolBar{
    
     [self.layer addSublayer:self.shapeCoverLayer];
    [self.layer addSublayer:self.shapeLayer];
    [self addSubview:self.toolBar];
}
- (void)hiddenToolBar{

    [self.recCoverPath removeAllPoints];
    [self.shapeCoverLayer removeFromSuperlayer];
    [self.recPath removeAllPoints];
    [self.shapeLayer removeFromSuperlayer];
    [self.toolBar removeFromSuperview];
    
    [self.innerScrollView cancelEdit];


    
}

#pragma mark -修改标题
- (void)modifyTitle:(UITapGestureRecognizer *)rec{
    self.innerDescTextV.editable = YES;
    self.isEditAlbumImage = YES;
    self.isEditTitle = YES;
    [self.editView.eidtTextView becomeFirstResponder];
    [self descTextViewText:self.albumTitleL.text isEdit:self.isEditAlbumImage];
}

#pragma mark -更新相册标题
- (void)changeAlbumTitle:(NSString *)title{
    if(title.charCount > 16) {
        [MBProgressHUD showhudMessage:@"相册名称不能超过16个字符" toView:self];
        return;
    }
    if(title.length <= 0 ) {
        title = @"未命名相册";
    }
    NSString *auuid = self.coverFrame.coverModel.auuid;
    
    if(auuid == nil) {
        return;
    }
    
    
    [PPNetworkService updateAlbumWithAlbumID:self.coverFrame.coverModel.albumID albumTitle:title albumDesc:nil privacy:nil privacySettings:nil commentSetting:nil coverKey:nil coverHost:nil tags:nil hotTags:nil order:nil callback:^(id data, NSError *error) {
        if (error == nil) {
            PPAlbumModel *album = [PPAlbumModel existingAlbumForUUID:auuid];
            
            BOOL modified = NO;
            
            // 更新album
            if(title != nil && !equal(title, album.title)) {
                album.title = title;
                modified = YES;
            }
            
            [[NSManagedObjectContext threadObjectContext] saveContext];
            
            
            [[PPAlbumManager sharedInstance] commitOfflineModifiedAlbumWithAlbumUUID:auuid completion:^{
                
            }];
            [[NSNotificationCenter defaultCenter] postNotificationName:PPAlbumManagerDidChangeLocalAlbumsNotification object:nil];
            
            [[NSNotificationCenter defaultCenter] postNotificationName:PPAlbumChanageTitle object:title];
            
//            self.albumTitleL.text = title;
//            self.coverFrame.coverModel.title = title;
        }else{
            self.albumTitleL.text = self.coverFrame.coverModel.title;
            
        }
    }];
    
}
@end
